﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tdv.Wfrp.CharacterGenerator.Domain;
using Tdv.Wfrp.CharacterGenerator.Domain.Characteristics;
using NHibernate;
using System.Data;
using System.Collections.ObjectModel;

namespace Tdv.Wfrp.CharacterGenerator.Infrastructure.Repositories
{
    public class CharacteristicRepository : BaseRepository,ICharacteristicRepository
    {

        public CharacteristicRepository(ISessionService sessionService) : base(sessionService)
        { }

        public ICollection<Characteristic> GetAll()
        {
            ICollection<Characteristic> retValue = new Collection<Characteristic>();
            using (ISession session = SessionService.CreateSession())
            {
                  retValue =  session.CreateCriteria<Characteristic>()
                                .List<Characteristic>();
            }

            return retValue;
        }

        public void Save(Characteristic characteristic)
        {
            using (ISession session = SessionService.CreateSession())
            {
                using (ITransaction trans = session.BeginTransaction())
                {
                    session.Save(characteristic);
                    trans.Commit();
                }
            }
        }
    }
}
